package handler

import (
	"application/basic/config"
	"application/internal/model"
	__ "application/proto"
	"context"
)

type VideServer struct {
	__.UnimplementedVideoServer
}

func (v *VideServer) List(_ context.Context, req *__.VideoListReq) (*__.VideoListResp, error) {
	var Video []*model.Video
	offset := (req.Page - 1) * req.PageSize
	config.DB.Offset(int(offset)).Where(int(req.PageSize)).Find(&Video)
	ListVideo := []*__.ListVideo{}
	for _, video := range Video {
		ListVideo = append(ListVideo, &__.ListVideo{
			Upload:            uint32(video.Upload),
			MemoryAddress:     uint32(video.MemoryAddress),
			TranscodingScheme: uint32(video.TranscodingScheme),
			VideoName:         video.VideoName,
			Format:            video.Format,
			Size:              float32(video.Size),
			VideoType:         video.VideoType,
		})
	}
	return &__.VideoListResp{
		List: ListVideo,
	}, nil
}
func (v *VideServer) Show(_ context.Context, req *__.CenterShowReq) (*__.CenterShowResp, error) {
	var center model.PersonalCenter
	config.DB.Find(&center)
	return &__.CenterShowResp{
		Name:     center.Name,
		Username: center.Username,
		Brief:    center.Brief,
		Address:  center.Address,
	}, nil

}
